﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Web;

namespace Imgur.Net.Util
{
    /// <summary>
    /// Helper extension methods for Uri's.
    /// </summary>
    public static class QueryStringHelper
    {
        /// <summary>
        /// Appends the given name/value pair to the query string and formats the tokens.
        /// </summary>
        /// <param name="uri">Uri to append values onto.</param>
        /// <param name="name">Name portion of the name-value pair.</param>
        /// <param name="value">Value portion of the name-value pair.</param>
        /// <returns></returns>
        public static Uri AddQuery(this Uri uri, string name, string value)
        {
            var query = HttpUtility.ParseQueryString(uri.Query);
            query.Add(name, value);

            var uriBuilder = new UriBuilder(uri)
            {
                Query = query.ToString()
            };

            return uriBuilder.Uri;
        }
    }
}
